package net.hn.hnms.job;

import lombok.extern.slf4j.Slf4j;
import net.hn.hnms.entity.FtpConfig;
import net.hn.hnms.service.FtpUploadService;
import java.util.Objects;

/**
 * 智呈物联 pan'sx
 * 2023/10/20 13:28
 * 1.0 version
 */
@Slf4j
public class ScheduleRunnalbe implements Runnable {



    private FtpConfig ftpConfig;


    @Override
    public void run() {
        log.info(ftpConfig.getName() + "定时任务开始执行");
        try {
            if("cron".equals(ftpConfig.getMode())) {
                FtpUploadService.cronUploadFile(ftpConfig);
            }else if ("listen".equals(ftpConfig.getMode())){
                FtpUploadService.listenUploadFile(ftpConfig);
            }
        } catch (Exception e) {
            log.error("定时任务报错e={}", e);
        }
        log.info(ftpConfig.getName() + "定时任务结束");

    }

    public ScheduleRunnalbe(FtpConfig ftpConfig) {
        this.ftpConfig = ftpConfig;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        return false;
    }

    @Override
    public int hashCode() {

        return Objects.hash(ftpConfig);
    }

}
